#include "DummyState.h"
#include <utils\Profiler.h>
#include "..\..\HUD.h"
#include "ui\UIDialog.h"

DummyState::~DummyState(void) {
}

bool DummyState::loadContent(ds::ResManager& resourceManager) {		
	m_ParticleSystem = static_cast<ds::ParticleManager*>(gEngine->getWorld().getNode("Particles"));
	/*
	m_Swimmer = new Swimmer();
	m_Swimmer->setCount(4);
	gEngine->addComponent(m_Swimmer);
	*/

	m_Dialog = new ds::UIDialog("test","UIMaterial",ds::Vec2(10,100),2,2);
	m_Dialog->addTextbox(1,0,0,"XPOS:","400");
	m_Dialog->addTextbox(3,1,0,"YPOS:","400");
	m_Dialog->addButton(20,1,1,"Small explosion");
	
	m_Dialog->registerListener(this);
	ds::Vec2 size = m_Dialog->resize();
	gEngine->getWorld().attachNode(m_Dialog,"HUD");

	m_NextDialog = new ds::UIDialog("test2","UIMaterial",ds::Vec2(10.0f,110.0f + size.y),2,3);
	
	m_NextDialog->addTextbox(5,0,0,"XPOS:","400");
	m_NextDialog->addTextbox(7,1,0,"YPOS:","400");
	m_NextDialog->addButton(21,1,1,"Big explosion");

	m_NextDialog->addCheckbox(8,0,2,"Hello world",true);

	m_NextDialog->registerListener(this);
	size = m_NextDialog->resize();
	gEngine->getWorld().attachNode(m_NextDialog,"HUD");

	m_FPDialog = new ds::UIDialog("test3","UIMaterial",ds::Vec2(10.0f,210.0f + size.y),2,2);

	m_FPDialog->addTextbox(5,0,0,"XPOS:","400");
	m_FPDialog->addTextbox(7,1,0,"YPOS:","400");
	m_FPDialog->addButton(31,1,1,"Floating particles");	
	m_FPDialog->registerListener(this);
	m_FPDialog->resize();
	gEngine->getWorld().attachNode(m_FPDialog,"HUD");



	HUD* m_HUD = new HUD();
	gEngine->getWorld().attachNode(m_HUD,"HUD");
	m_Core = new GameCore();
	m_Core->loadContent(resourceManager);		

	m_EnemySprites = new ds::DynamicSpriteNode("Enemies","TexturesMaterial");
	//m_EnemySprites->setActive(false);
	gEngine->getWorld().attachNode(m_EnemySprites,"HUD");
	m_Particles = new FloatingParticles(m_EnemySprites);

	return true;
}

bool DummyState::update(float elapsedTime) {
	m_Particles->update(elapsedTime);
	return true;
}

void DummyState::OnChar(char ascii,unsigned int keyState) {
	if ( isActive() ) {
		/*
		if ( ascii == 's' ) {
			m_ParticleSystem->start(ds::Vec3(400,400,0),"RingExplosion");
			m_ParticleSystem->start(ds::Vec3(400,400,0),"DebrisExplosion");
		}	
		if ( ascii == 'i' ) {
			m_ParticleSystem->start(ds::Vec3(200,200,0),"ImpactExplosion");
		}	
		if ( ascii == 'p' ) {
			gProfiler->print();
		}
		if ( ascii == 'd' ) {
			gEngine->debug();
		}
		if ( ascii == '1' ) {
			gEngine->getActionManager().startAction("Blitz");
		}
		if ( ascii == '2' ) {
			gEngine->getActionManager().startAction("Flash");
		}
		if ( ascii == '3' ) {
			gEngine->getActionManager().stopAction("Flash");
		}
		if ( ascii == '4' ) {
			gEngine->getActionManager().startAction("GrayFade");
		}
		if ( ascii == '5' ) {
			gEngine->getActionManager().stopAction("GrayFade");
		}
		*/
	}
}

void DummyState::onUIEvent(const ds::IUIEvent& event) {
	if ( event.getControlID() == 20 ) {
		float x = ds::dialog::getFloat(m_Dialog,1,100.0f);
		float y = ds::dialog::getFloat(m_Dialog,3,100.0f);
		m_ParticleSystem->start(ds::Vec3(x,y,0.0f),"ImpactExplosion");
	}
	if ( event.getControlID() == 21 ) {
		float x = ds::dialog::getFloat(m_NextDialog,5,100.0f);
		float y = ds::dialog::getFloat(m_NextDialog,7,100.0f);
		m_ParticleSystem->start(ds::Vec3(x,y,0.0f),"RingExplosion");
		m_ParticleSystem->start(ds::Vec3(x,y,0.0f),"DebrisExplosion");
	}
	if ( event.getControlID() == 31 ) {
		float x = ds::dialog::getFloat(m_NextDialog,5,100.0f);
		float y = ds::dialog::getFloat(m_NextDialog,7,100.0f);
		m_Particles->add(ds::Vec2(x,y),20,80.0f,90.0f);
	}
}
